package multiplex.view;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;

import multiplex.facade.Facade;
import multiplex.facade.LocalizacaoFacade;
import multiplex.model.Localizacao;
import multiplex.model.SalaTipo;
import multiplex.model.Sessao;
import multiplex.model.Sala;

public class IFTelaCadastraSalas extends InternalFramePrincipal{
	
	private JLabel labelLocalizacao;   
    private JFormattedTextField textoLocalizacao; 
    private JLabel labelTipo;  
    private JRadioButton botaoStadium;
    private JRadioButton botaoHall;
    private JRadioButton botaoTheater;
    private JLabel label3D;  
    private JRadioButton botao3DON;
    private JRadioButton botao3DOFF;
    
	private JButton botaoInserir;  
  
    public IFTelaCadastraSalas() {   
        super("Cadastro de Salas");   
        // TODO Auto-generated constructor stub   
           
        final Container conteudo = getContentPane();   
        conteudo.setLayout(new GridLayout(4,2,5,5));   
  
        labelLocalizacao = new JLabel("Localiza��o");     
        textoLocalizacao = new JFormattedTextField();         
           
        labelTipo = new JLabel("Tipo"); 
        botaoStadium = new JRadioButton("Stadium[520]");
        botaoHall = new JRadioButton("Hall[390]");
        botaoTheater = new JRadioButton("Theater[260]");
        
        label3D = new JLabel("3D"); 
        botao3DON = new JRadioButton("Sim");
        botao3DOFF = new JRadioButton("N�o");
        botaoInserir = new JButton("inserir");
        
        conteudo.add(labelLocalizacao);   
        conteudo.add(textoLocalizacao); 
        conteudo.add(labelTipo); 
        conteudo.add(botaoStadium); 
        conteudo.add(botaoHall); 
        conteudo.add(botaoTheater); 
        conteudo.add(label3D); 
        conteudo.add(botao3DON); 
        conteudo.add(botao3DOFF); 

        conteudo.add(botaoInserir);   
        
        botaoInserir.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Facade fachada = new Facade(); 
				LocalizacaoFacade locfachada = new LocalizacaoFacade();
				List<Sessao> Sessoes = new ArrayList<Sessao>();
				
				SalaTipo stadium = multiplex.model.SalaTipo.STADIUM;
				SalaTipo hall = multiplex.model.SalaTipo.HALL;
				SalaTipo theater = multiplex.model.SalaTipo.TEATHER;
	
				try { 
					List<Localizacao> localizacoes = locfachada.getLocalizacao(textoLocalizacao.getText());
					Localizacao Localizacao = localizacoes.get(0);
					
					if(botaoStadium.isSelected()){
						fachada.cadSala(new Sala(stadium, botao3DON.isSelected(), Localizacao, Sessoes));
					}
					else if(botaoHall.isSelected()){
						fachada.cadSala(new Sala(hall, botao3DON.isSelected(), Localizacao, Sessoes));
					}
					else if(botaoTheater.isSelected()){
						fachada.cadSala(new Sala(theater, botao3DON.isSelected(), Localizacao, Sessoes));
					}
					
					JOptionPane.showMessageDialog(conteudo, "Text Message","MessageBox Title", EXIT_ON_CLOSE);
				} catch (Exception e) { 
					e.printStackTrace(); 
					}
			}
		});
 
    }      
  
}  
